<template>
	<view>
		<contact-animation :share="isShowAnimation" @display="closeAnimation"></contact-animation>

		<!-- 搜索组件 -->
		<my-search @clickSearch="gotoSearch" :searchText="searchText" :bgColor="searchBgColor"
			:boxBgColor="searchBoxBgColor"></my-search>

		<!-- 2，导航组件 -->
		<contact-navbar :activeIndex="activeIndex" @changeActiveItem="changeActiveItem"></contact-navbar>

		<!-- 3，朋友列表 -->
		<contact-friend-list :showList="showList"></contact-friend-list>
	</view>
</template>

<script>
	//引入子组件
	import contactHead from './contact-child/contact-head.vue'
	import contactNavbar from './contact-child/contact-navbar.vue'
	import contactTool from './contact-child/contact-tool.vue'
	import contactAnimation from './contact-child/contact-animation.vue'
	import contactFriendList from './contact-child/contact-friend-list.vue'

	//导入公共组件
	import mySearch from '@/components/common/my-search/my-search.vue'

	//获取网络请求
	import {
		getRelationList
	} from '@/api/http/msg/relation.js'

	export default {
		components: {
			contactHead,
			contactNavbar,
			contactTool,
			contactAnimation,
			contactFriendList,
			mySearch
		},
		data() {
			return {
				isShowAnimation: false,
				activeIndex: 0,
				showPop: false,
				showShade: false,
				showList: [],
				userId: uni.getStorageSync('userId'),
				searchBgColor: '#fff',
				searchBoxBgColor: 'rgba(245, 245, 245, 1)',
				searchText: '搜索好友/群组'
			}
		},
		methods: {
			//1，关闭弹框
			closeAnimation() {
				this.isShowAnimation = false
			},
			//2，跳转 有关联的搜索页面
			gotoSearch() {
				uni.navigateTo({
					url: '/pages/msg/search-relation/search-relation'
				})
			},
			//3，修改状态后，查询
			changeActiveItem(item) {
				if (item == undefined) {
					return
				}
				//console.log(item)
				this.activeIndex = item.id

				this.getFriendList(item.fid)

				wx.setNavigationBarTitle({
					title: item.text
				})
			},

			//4，获取列表数据
			getFriendList(fid) {
				getRelationList(this.userId, fid).then(res => {
					if (res.data.pubInfo.code !== 0) {
						return uni.$showMsg(res.data.pubInfo.message);
					}

					this.showList = res.data.busInfo
				})
			}
		},
		onLoad() {
			wx.setNavigationBarTitle({
				title: '好友'
			})
			
			this.getFriendList(2)
		},
		onNavigationBarButtonTap() {
			this.$nextTick(() => {
				setTimeout(() => {
					this.isShowAnimation = true;
				}, 10);
			});
		},
		onShow() {
			/* console.log(this.activeIndex)
			this.activeIndex = 0
			this.getFriendList(2) */
			
		}
	}
</script>

<style>

</style>